Results 1 to 4 of 4

Thread: examples for implementation of qsimplex algorithm

  1. #1
    Join Date
    Sep 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default examples for implementation of qsimplex algorithm

    I have a source file for qsimplex, which is given in the link below:

    http://www.oschina.net/code/explore/...qsimplex_p.cpp

    The header file is given in the link:

    http://www.oschina.net/code/explore/...w/qsimplex_p.h


    I have a text file with some data like:

    Maximize:

    obj: 3e-06 A - 3e-06 B + 2.7e-01 F

    constraints:

    RXN1: -1 A + 1 B -1 C + 1 D -1 E -1 F = 0

    RXN2: -1 A + 1 B -1 C + 1 D -1 E -1 F = 0

    RXN3: -1 A + 1 B -1 C + 1 D -1 E -1 F = 0

    RXN4: -1 A + 1 B -1 C + 1 D -1 E -1 F = 0

    ... many constraints like this

    Bounds:

    A >= 0
    B <= 100
    C >= 0

    .....
    ...........many bounds like this.

    I wrote a small program to get the data from this file:

    #include <iostream>
    #include <fstream>
    #include <string>


    using namespace std;

    int main()
    {
    ifstream ifs("Metabolism.txt");
    string line;
    while(getline(ifs,line)) {
    cout << "[ " << line << " ]" << endl;
    }
    system("PAUSE");
    }

    I want some help to parse all the constraints and bounds as inputs and get the maximum value of the objective function as the output using the above lpsolver header file.

    I want to see some examples of implementation of this Linear programming solver in order to use it. Could you anyone suggest some examples?

    Thanks.
    Last edited by navy1991; 18th September 2013 at 14:28.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: examples for implementation of qsimplex algorithm

    I would suggest to use QFile + QTextStream for reading the data.
    QTextStream's readLine() returns a QString and QString has nicer methods for substring operations, can be used together with QRegExp, etc.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: examples for implementation of qsimplex algorithm

    Hi anda_skoa,
    Since I am a newbie to Qt, I do not know how to use QFile + QTextStream.

    I have written a small program like:

    Qt Code:
    1. #include <iostream>
    2. #include <string>
    3. #include <map>
    4.  
    5. typedef double qreal;
    6.  
    7. struct QSimplexVariable
    8. {
    9. QSimplexVariable() : result(0), index(0) {}
    10. qreal result;
    11. int index;
    12. };
    13.  
    14. struct QSimplexConstraint
    15. {
    16. QSimplexConstraint() : constant(0), ratio(Equal), artificial(0) {}
    17. enum Ratio {LessOrEqual = 0,Equal,MoreOrEqual};
    18. float constant;
    19. Ratio ratio;
    20. std::pair<QSimplexVariable *, qreal> helper;
    21. QSimplexVariable * artificial;
    22. };
    23.  
    24.  
    25. QSimplexConstraint parseMe(const std::string& str)
    26. {
    27. return QSimplexConstraint() ; // I should fill some thing more here to parse the string as a QsimplexConstraint.
    28. }
    29.  
    30. using namespace std;
    31.  
    32. int main()
    33. {
    34. std::string constraintString;
    35. cout << "Enter a constraint string: ";
    36. getline(cin, constraintString);
    37. QSimplexConstraint qc = parseMe( constraintString );
    38. //...
    39. }
    To copy to clipboard, switch view to plain text mode 

    Could you please help me to complete my code from here.

    Thanks,
    Navy1991.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: examples for implementation of qsimplex algorithm

    You don't have to use Qt.
    If you are more comfortable with STL types such as ifstream and string, please by all means use those.

    Cheers,
    _

Similar Threads

  1. A* algorithm
    By Ichi in forum Qt Programming
    Replies: 2
    Last Post: 31st March 2013, 17:31
  2. Replies: 1
    Last Post: 7th March 2013, 00:30
  3. Help to set up sorting algorithm
    By Quasar in forum General Programming
    Replies: 2
    Last Post: 12th June 2012, 00:16
  4. No Response when Algorithm runs...
    By revellix in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2011, 17:24
  5. Dijkstra's Algorithm
    By therealjag in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2006, 10:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.